package com.jfshop.framework.util;

public class SerialNumberUtil {
	public static final String[] numAndLetter= { "0", "1", "2", "3", "4", "5", "6", "7", "8", 
		"9", "a", "A", "b", "B", "c", "C", "d", "D", "e", "E", "f", "F", "g", "G", "h", 
		"H", "i", "I", "j", "J", "k", "K", "l", "L", "m", "M", "n", "N", "o", "O", "p", 
		"P", "q", "Q", "r", "R", "s", "S", "t", "T", "u", "U", "v", "V", "w", "W", "x",
		"X", "y", "Y", "z", "Z" };
	
	public static final String[] numAndLetterStr= {"A","B","C","D","E","F","G","H","I","J","K","L","M","N",
		"O","P","Q","R","S","T","U","V","W","X","Y","Z"};
	
	private SerialNumberUtil() {
		throw new RuntimeException("util class is static");
	}
	
	/**
	 * 得到当前时间(long)的字符串，13位
	 * @param time
	 * @return
	 */
	public static String getTimeString13(long time) {
		
		String currentTimeS = String.valueOf(time);
		int beginIndex = currentTimeS.length() > 13 ? currentTimeS.length() - 13 : 0;
		
		return currentTimeS.substring( beginIndex );
	}
	
	/**
	 * 得到随机的字符串，包含大小写字母和数字
	 * @param length 返回字符串的长度
	 * @return
	 */
	public static String getRadomString( int length ) {
	
		StringBuffer buffer = new StringBuffer();
		for( int i=0; i<length; i++ ) {
			
			int index = (int)( Math.random() * 62 );
			buffer.append( numAndLetter[index] );
		}
		
		return buffer.toString();
	}
	
	/**
	 * 得到随机的字符串，包含大小写字母和数字
	 * @param length 返回字符串的长度
	 * @return
	 */
	public static String getRadomStr( int length ) {
	
		StringBuffer buffer = new StringBuffer();
		for( int i=0; i<length; i++ ) {
			
			int index = (int)( Math.random() * 26 );
			buffer.append( numAndLetterStr[index].toUpperCase() );
		}
		
		return buffer.toString();
	}
}
